package name.huzhenbo.java.algorithm.talent;

import java.util.Arrays;

class TriangleEdgesFinder {
    public void find(int[] input) {
        int count = 0;
        for (int i = 0; i < input.length; i++) {
            for (int j = i + 1; j < input.length; j++) {
                for (int k = j + 1; k < input.length; k++) {
                    if (isValid(input, i, j, k)) {
                        count++;
                        print(input, i, j, k);
                    }
                }
            }
        }
        printTotalCount(count);
    }

    private void printTotalCount(int count) {
        System.out.println("Total count: " + count);
    }

    private void print(int[] input, int i, int j, int k) {
        int[] edges = {input[i], input[j], input[k]};
        Arrays.sort(edges);
        System.out.println("x: " + edges[0] + " , y: " + edges[1] + " , z: " + edges[2]);
    }

    private boolean isValid(int[] input, int i, int j, int k) {
        return input[i] + input[j] > input[k] && input[i] + input[k] > input[j] && input[j] + input[k] > input[i];
    }
}
